home *** CD-ROM | disk | FTP | other *** search
- Path: mayne.ugrad.cs.ubc.ca!not-for-mail
- From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
- Newsgroups: comp.lang.c
- Subject: Re: Integers -> Pointers -> Integers
- Date: 16 Apr 1996 12:58:54 -0700
- Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
- Message-ID: <4l0u5uINN6sd@mayne.ugrad.cs.ubc.ca>
- References: <DpoyFt.Ls2@uns.bris.ac.uk>
- NNTP-Posting-Host: mayne.ugrad.cs.ubc.ca
-
- In article <DpoyFt.Ls2@uns.bris.ac.uk>,
- Chris Davis-Pipe <chris@pact.srf.ac.uk> wrote:
- >Hi,
- >
- >Suppose i have a pointer to a struture.
- >
- >Is there a way that I can store that pointer and others like it in an array
- >of integers ?
-
- Why not use an array of the appropriate pointer types?
-
- >Obviously, at some point I am going to want to convert the entry in the array
- >back to a pointer to the structure.
-
- If you are looking for a way to set up a generic array that can hold any type,
- make it an array of:
-
- union data {
- void *p;
- unsigned long u;
- long i;
- double d;
- }
-
- Now if you make an array A[] of union data, then you can do these assignments
- with confidence:
-
- A[3].d = 4.00;
- A[4].p = "String";
- A[5].i = 3;
-
- and so on.
- --
- I'm not really a jerk, but I play one on Usenet.
-